package com.nuorui.module.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.annoation.NoNeedLogin;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.module.system.domain.form.ConfigForm;
import com.nuorui.module.system.domain.query.ConfigQueryForm;
import com.nuorui.module.system.domain.vo.ConfigVO;
import com.nuorui.module.system.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 配置信息
 *
 * @author: Fred
 * @email 453086@qq.com
 * @create: 2021-10-22 10:42
 */
@RestController
@RequiredArgsConstructor
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_CONFIG)
public class ConfigController {

    private final ConfigService configService;

    @GetMapping("/configs/page")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public ResponseDTO<IPage<ConfigVO>> page(Page page, ConfigQueryForm queryForm) {
        return configService.getConfigsPage(page, queryForm);
    }

    @PostMapping("/configs")
    @ApiOperation(value = "新增配置", notes = "新增配置")
    public ResponseDTO<String> saveConfig(@Valid @RequestBody ConfigForm configForm) {
        return configService.saveConfig(configForm);
    }

    @PutMapping("/configs/{configId}")
    @ApiOperation(value = "更新配置", notes = "更新配置")
    public ResponseDTO<String> updateConfig(@PathVariable("configId") Long configId, @RequestBody @Valid ConfigForm configForm) {
        return configService.updateConfig(configId,configForm);
    }

    @DeleteMapping("/configs/{configId}")
    @ApiOperation(value = "删除配置", notes = "删除配置")
    public ResponseDTO<String> removeConfig(@PathVariable("configId") Long configId) {
        return configService.removeConfig(configId);
    }
}
